package dao

import (
	"yundian/internel/app/helper"
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/dingo/global"
)

// 获取动销门店
func (d *StatisticsDao) GetPlaceIdsByOrders(dateStr string) *dingo.ErrorWrap {
	var ids []int
	sql := "SELECT place_id FROM temp_orders" + helper.ConvSpecStr(dateStr) + " GROUP BY place_id"
	db := global.Orm.Raw(sql).Find(&ids)
	return dingo.ErrorIf(db.Error, ids)
}

// 获取动销商户
func (d *StatisticsDao) GetPlaceUserIdsByOrders(dateStr string) *dingo.ErrorWrap {
	var ids []int
	sql := "SELECT o.user_id FROM temp_orders_" + helper.ConvSpecStr(dateStr) + " o LEFT JOIN users u ON o.user_id = u.id " +
		"WHERE u.is_admin = 3 and u.is_delete != 1 GROUP BY o.user_id"
	db := global.Orm.Raw(sql).Find(&ids)
	return dingo.ErrorIf(db.Error, ids)
}

